//
// Created by Administrator on 2025/7/18.
//

#include <iostream>
#include "string"
#include <filesystem>
#include <fstream>
#include <sstream>

#ifndef CTEST_TEST7_H
#define CTEST_TEST7_H


class Test7 {

private:
    int age;
    std::string *name;

public:
    Test7(std::string c) : age(1), name(&c) {}

    void foo();
};


struct Test7Struct1 {
    int a;
    std::string *b;
    Test7Struct1 *next;
};

class Test8 {

private:
    int a;
    std::string *b;

public:
    Test8(int a, std::string *c) : a(a), b(c) {};

    Test8(const Test8 &obj) {
        this->a = obj.a;
        this->b = obj.b;
    }

    ~Test8() {
        std::cout << "destory";
    }

    void test();

    friend void test2(Test8 &a) {
        //友元没有this指针但是他能对象的private字段
    }

    inline void foo3();


    static void foo4() {
    }

protected:

    void foo13() {

    }
};

class Test9 : protected Test8 {

public:
    Test9(int a, std::string *c) : Test8(a, c) {};
};

class Test10 {

public:
    int *operator+(Test10 &t) {
        int *a = new int(1);
        return a;
    }
};

class Animal1 {

private:
    const char *name;
    int age;

public:
    Animal1(const char *name, int age) : name(name), age(age) {};

    void foo() {
        std::cout << this->name << this->age << std::endl;
    }

//    纯虚函数 类似于 抽象方法
    virtual void foo2() = 0;

//    虚函数 表示可以被 覆盖
    virtual void foo3() {

    }

    virtual void foo4() const {
        std::cout << "parent foo4";
    };
};

class Dog1 : public Animal1 {

public:
    Dog1() : Animal1("dawd", 1) {};

    void foo2() override {

    }

    void foo3() override {
        Animal1::foo3();
    }

    void foo4() const override {
        Animal1::foo4();
        std::cout << "child foo4";
    }
};

class Test7TestFile {

private:
    mutable int a;

public:
    Test7TestFile() : a(1) {};

    void foo() {
        std::ofstream of;
        of.open("D:\\python_source.txt", std::ios::out);
        of << "dwad" << std::endl;

        std::string content;
        std::istringstream iif("dawdaw");
        iif >> content;
        std::clog << content;
    }

    void foo2(int *c, std::initializer_list<int> varargs);

    static int foo3(const std::string &vc);

    void foo4() const {
    }
};

class MyException2 : public std::exception {

public:
    [[nodiscard]] const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
};

template<typename T>
// 简单要求 简单要求是结构体 https://www.cnblogs.com/Cattle-Horse/p/16637811.html
concept is_num2 = std::is_integral<T>().value;
//concept is_num = requires(T a) {
//复合要求 右边是 template concept
//    { a + 1 } -> std::same_as<int>;
//};

template<is_num2 T>
void test7Foo1(T t) {
}

// c语言中的枚举全局有效名称不能重复
// 使用预定义进行枚举定义 #define TEST_ENUM 1
enum Test7Enum1 {
    A = 0, B, C = 10086
};

void signalHandler(int sigType);

constexpr int getIndex(int a, int b);

class Test7C3 {

private:
    mutable char *c;

public:
    Test7C3(char* c) : c(c) {};

    void foo1();

    void foo2() const;
};

#endif //CTEST_TEST7_H
